package com.egao.common.manage.student;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.student.constants.StudentConstants;
import com.egao.common.module.student.entity.Student;
import com.egao.common.module.student.entity.vo.StudentIntenVO;
import com.egao.common.module.student.service.StudentService;
import com.egao.common.module.student.service.impl.StudentResumeServiceImpl;
import com.egao.common.module.system.constants.DictConstants;
import com.egao.common.module.system.entity.Dict;
import com.egao.common.module.system.service.DictService;
import com.egao.common.module.system.service.QsSchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 学生问卷管理 就业意向管理
 *
 * @author lym
 */
@Api(tags = "学生问卷管理(就业意向管理)")
@RestController
@RequestMapping("${api}")
public class StudentIntenController extends BaseController {
    @Autowired
    private StudentService studentService;
    @Autowired
    private QsSchoolService qsSchoolService;
    @Autowired
    private DictService dictService;

    private final String title = "学生问卷管理";

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "学生就业意向详情")
    @ApiOperation(value = "学生就业意向详情")
    @GetMapping("/student/inten/detail")
    public JsonResult detail() {
        List<Dict> dcList = dictService.cacheList("dc_lqyxdm");
        List<Dict> companyNature = dictService.cacheList(DictConstants.COMPANY_NATURE);
        List<Dict> companyIndustry = dictService.cacheList(DictConstants.COMPANY_INDUSTRY);
        List<Dict> companyScale = dictService.cacheList(DictConstants.COMPANY_SCALE);
        Map<String, List<Dict>> stringListMap = studentService.dictMap();
        stringListMap.put("dcLqyxdm", dcList);
        stringListMap.put("companyNature", companyNature);
        stringListMap.put("companyIndustry", companyIndustry);
        stringListMap.put("companyScale", companyScale);

        return JsonResult.ok().setData(studentService.getStudentInten(getLoginUserId()))
                .put("dictMap", stringListMap)
                .put("qsTree", qsSchoolService.treeAll());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "提交就业意向", result = true)
    @ApiOperation(value = "提交就业意向")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "StudentIntenVO", value = "StudentIntenVO", required = true, dataType = "StudentIntenVO")
    })
    @PutMapping("/student/inten/update")
    public JsonResult update(@RequestBody StudentIntenVO studentIntenVO) {
        // 保存简历
        return studentService.updateStudentInten(studentIntenVO, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "技能语言和证书")
    @ApiOperation(value = "学生就业意向详情")
    @GetMapping("/student/inten/dict")
    public JsonResult dictMap() {
        List<Dict> dcList = dictService.cacheList("dc_lqyxdm");
        Map<String, List<Dict>> stringListMap = studentService.dictMap();
        stringListMap.put("dcLqyxdm", dcList);
        return JsonResult.ok().setData(stringListMap);
    }

    @PreAuthorize("hasAuthority('student')")
    @OperLog(value = title, desc = "提交就业意向", result = true)
    @ApiOperation(value = "提交就业意向")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "StudentIntenVO", value = "StudentIntenVO", required = true, dataType = "StudentIntenVO")
    })
    @PutMapping("/student/inten/temporary")
    public JsonResult temporary(@RequestBody StudentIntenVO studentIntenVO) {
        // 暂存保留学生填写信息，不会改变提交状态
        return studentService.temporaryStudentInten(studentIntenVO, getLoginUserId());
    }

    @PreAuthorize("hasAuthority('student')")
    @ApiOperation(value = "判断是否有上传了简历")
    @GetMapping("/student/inten/upload")
    public JsonResult doget() {
        Student student = studentService.getByUserId(getLoginUserId());
        if (student.getQuestionnaireState().equals(StudentConstants.STUDENT_QUESTIONNAIRE_SUBMIT)) {
            return JsonResult.ok().setData(student.getId());
        } else {
            return JsonResult.error("暂未提交简历");
        }
    }

}
